from django.db import models


class Student(models.Model):
    name = models.CharField(max_length=36)
    gender = models.IntegerField()
    age = models.IntegerField()
    time = models.DateTimeField()
    addr = models.CharField(max_length=256, null=True)

    def __str__(self):
        return 'name=%s, gender=%s, age=%s, time=%s, addr=%s\n' % ( self.name,
                self.gender, self.age, self.time.strftime('%F %T'), self.addr)

    def __repr__(self):
        return self.__str__()


class Book(models.Model):
    name = models.CharField(max_length=128)
    price = models.IntegerField()
    year = models.IntegerField()
    author = models.CharField(max_length=64)

    def __str__(self):
        return 'name=%s price=%s year=%s author=%s' % ( self.name, self.price, self.year, self.author)

    def __repr__(self):
        return self.__str__()


class Phone(models.Model):
    sn = models.CharField(max_length=64, primary_key=True)
    brand = models.CharField(max_length=64)


class Father(models.Model):
    name = models.CharField(max_length=128)


class Child(models.Model):
    name = models.CharField(max_length=128)
    father = models.ForeignKey(Father)


class Tag(models.Model):
    desc = models.CharField(max_length=128)


class Article(models.Model):
    title = models.CharField(max_length=128)
    tag = models.ManyToManyField(Tag)


class Private(models.Model):
    keyid = models.CharField(max_length=128)


class Public(models.Model):
    keyid = models.CharField(max_length=128)
    private = models.OneToOneField('Private', null=True)


class M(models.Model):
    name = models.CharField(max_length=128)
    gender = models.IntegerField(default=1)
    addr = models.CharField(max_length=128, null=True)
    create = models.DateTimeField(auto_now_add=True)
    modify = models.DateTimeField(auto_now=True)
